/*
 * Created on 2006-2-23
 *
 */
package org.faquir.license;

import rainbow.*;

import java.io.File;
import java.util.Arrays;

import org.faquir.license.util.CodeFactory;
import org.faquir.license.util.CodePair;

public class RainbowLicense implements License
{
    final static public int MAX_SERVERS = 10; // the maximum number of servers

    // for EnumServer

    final static public int NUM_KEY_CELLS = 64; // Number of cells in the SSP

    // key

    final static public int MIN_QUERY_SZ = 8; // Minimum Query length allowed

    final static public int MAX_QUERY_SZ = 56;// Maximum Query length allowed

    final static public byte MAX_CELL_DATA_LEN = 4;

    final static public byte MAX_CELL_ADD_LEN = 2;

    // OS driver type constants
    final static public byte RB_WINNT_SYS_DRVR = 5;

    final static public byte RB_WIN95_SYS_DRVR = 7;

    final static public byte RB_NW_LOCAL_DRVR = 8;

    final static public byte RB_WINNT_SYS_UNKNOWN = 10;

    public boolean canUse(File license) throws Exception
    {
        SentinelSuperpro sentinel = new SentinelSuperpro();
        byte[] apiPacket = new byte[sentinel.API_PACKET_SZ];
        int developerID = 0x676F;
        int address = 0x10;
        int status = 0;
        char[] response = new char[4];
        long[] response32Null = new long[0];
        
        CodePair cp = CodeFactory.getCodePare();

        status = sentinel.RNBOsproFormatPacket(apiPacket, apiPacket.length);
        System.out.println("error in RNBOsproFormatPacket:"+status);
        status = sentinel.RNBOsproInitialize(apiPacket);
        System.out.println("error in RNBOsproInitialize:"+status);
        status = sentinel.RNBOsproFindFirstUnit(apiPacket, developerID);
        System.out.println("error in RNBOsproFindFirstUnit:"+status);
        status = sentinel.RNBOsproQuery(apiPacket, address, cp.getRequest(),
                response, response32Null, 4);
        System.out.println("error in RNBOsproQuery:"+status);
        if (status == 0 && Arrays.equals(response,cp.getResponse()))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
